/*
    RExLib project, file dbconnector.cpp
    Copyright (C) 2012  Sarvaritdinov Ravil ra9oaj@gmail.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/


#ifndef DBCONNECTOR_H
#define DBCONNECTOR_H

#include <iostream>
#include <string.h>
#include <malloc.h>
#include <dlfcn.h>

#include "dbconnectorprivate.h"

namespace rex {

class DBconnector : public DBconnectorPrivate
{

public:
  DBconnector();
  DBconnector ( const DBconnector& other );
  ~DBconnector();
  virtual DBconnector& operator= ( const DBconnector& other );
  bool operator== ( const DBconnector& other ) const;
  void setDBdriver ( const char *driver );
  void setDBName ( const char *name );
  void setDBUser ( const char *username, const char *passw = 0 );
  void setSSLConnection ( bool sslf = true );
  void setUnixConnection ( bool unixf = true );
  bool openDB ( const char *host, uint port = 0 );
  bool closeDB();
  int dbState() const;
  char* value ( int val );
  unsigned long long rowCount() const;
  unsigned long long affectedRows() const;
  unsigned fieldCount() const;
  int query ( const char* qry );
  bool next();
  bool first();
  bool seek ( unsigned long long pos );
  int nativeErrorNo() const;
  const char* nativeErrorString() const;
  int errorCode() const;
  const char* errorString() const;

private:
  int _gstate;
  int _gerror;
  char *_drname;
  void *_dldriver;
  DBconnectorPrivate *_driver;

  char *_dbname, *_dbuser, *_dbpasswd;
};

}
#endif // DBCONNECTOR_H
